package com.oocl.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.oocl.dto.FoodDTO;
import com.oocl.dto.MUserDTO;
import com.oocl.dto.MUserFoodListDTO;
import com.oocl.exception.MyException;
import com.oocl.service.FoodService;
import com.oocl.service.MuserService;
import com.oocl.service.impl.FoodServiceImpl;
import com.oocl.service.impl.MuserServiceImpl;
import com.oocl.util.PropertiesFactory;
import com.oocl.util.RequestUtil;


public class FoodList2CServlet extends HttpServlet {

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		System.out.println("FoodList2CServlet...");
		FoodService fSer = new FoodServiceImpl();
		MuserService mSer = new MuserServiceImpl();
		String icnum = request.getParameter("mid");
		icnum = icnum.trim();
		System.out.println(icnum);
		String ftype = request.getParameter("ftype");
		if(null!=ftype){
			
			ftype = ftype.trim();
		}
		System.out.println(ftype);
		List<FoodDTO> fList = null;
		MUserDTO mUser = null;
		try {
			mUser = mSer.loadMuserDTOByIcnum(icnum);
		    fList = fSer.loadFoodDTOs(icnum,ftype);
			MUserFoodListDTO ml = new MUserFoodListDTO();
			ml.setfList(fList);
			ml.setmUser(mUser);
			String json = RequestUtil.wrapToJson(ml);
			System.out.println(json);
			response.setCharacterEncoding("utf-8");
			response.getWriter().write(json);
		} catch (MyException e) {
			throw e;
		}
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		doGet(request,response);
	}

}
